package controllers.list;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import channel.ChannelUtils;
import controllers.log.LogAction;
import model.ChannelCondition;
import play.Play;
import play.mvc.Controller;


public class ProjectListAction extends Controller{
	
	
	private static ChannelUtils channelUtils = new ChannelUtils();
	
	/**
	 * 列举项目目录
	 * 
	 * @author yutao
	 * @date 2017年5月15日下午2:37:34
	 */
	public static void query(ChannelCondition condition){
		
		/*String cdPath = "cd /home/jenkins/workspace/ \n";
		String lsCmd="ls \n";
		
		Map<String, Object> execMap = channelUtils.commandExec(cdPath + lsCmd);
		List<String> execList =  (List<String>) execMap.get("result");*/
		
		String path = Play.configuration.getProperty("pack.path");//从jenkins中获取项目名称列表
		Map<String, Object> execMap = new HashMap<String, Object>();
		File file = new File(path);
		List<String> result = new ArrayList<String>();
		if(file.exists()){
			execMap.put("isError", true);
			File[] listFiles = file.listFiles();
			for(File fi : listFiles){
				result.add(fi.getName());
			}
			execMap.put("result", result);
		}else{
			execMap.put("isError", false);
			result.add(path + "该目录为空");
			execMap.put("result", result);
		}
		
		List<String> execList =  (List<String>) execMap.get("result");
		render(execList);
	}

}
